package com.example.util;

import cn.hutool.setting.dialect.Props;

import java.io.IOException;
import java.util.Properties;

public class BeanFactroy {
    static Props props = new Props("bean.properties");

    public static <T> T createBean(Class<T> clazz){

        //反射技术 调用无参构造
        String simpleName = clazz.getSimpleName();
        //接口对应的实现类的全限定名
        String className = props.getProperty(simpleName);

        try {
            //得到实现类Class对象
            Class<?> aClass = Class.forName(className);
            return (T)aClass.newInstance();

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        return null;
    }
}
